import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
let store = new Vuex.Store({
    state: {
        num: 123,
        list: [
            {
                name: '张三',
                age: 18
            },
            {
                name: '李四',
                age: 20
            },
            {
                name: '唐麻子',
                age: 30
            },
            {
                name: '王发发',
                age: 24
            }
        ],
        info: {
            name: '王发发',
            age: 18
        }
    },
    getters: {
        more(state) {
            // return state.list.filter((item) => item.age > 20);
            return function (age) {
                return state.list.filter((item) => item.age > age);
            };
        }
    },
    mutations: {
        addNum(state, val) {
            state.num += val.num;
        },
        addHeight(state) {
            Vue.set(state.info, 'height', 178);
            // state.info.height = 178;
        }
    }
});

export default store;
